package controller.user;

import Message.DTO.ShoppingCartDTO;
import Message.Result;
import Message.entity.ShoppingCart;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import service.ShoppingCartService;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "购物车相关接口")
@Slf4j
@RequestMapping("/user/shoppingCart")
@RestController
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 查看购物车
     * @return
     */
    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result list( ) {
        log.info("查看购物车");
        List<ShoppingCart> list = shoppingCartService.list();
        return Result.success(list);
    }
    @ApiOperation("购物车添加功能")
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {

    log.info("添加了购物车",shoppingCartDTO);

    shoppingCartService.addCart(shoppingCartDTO);
     return Result.success();
    }
    @ApiOperation("购物车删除一个商品")
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {

        log.info("删除的商品是：",shoppingCartDTO);


        shoppingCartService.sub(shoppingCartDTO);
        return Result.success();

    }

       @ApiOperation("清空购物车列表")
    @DeleteMapping("/clean")
    public Result clean() {
        log.info("该用户购物车列表已经删除");

        shoppingCartService.clean();
        return Result.success();
       }






}
